At this point I am going to assume you are familiar with CGI and the Windows/DOS scripting environment, and that you have setup the server in its "out of the box" configuration.
The standard shell that comes with Windows is the DOS command interpreter
COMMAND.COM
. There are some
3rd party alternatives
which offer far
greater capabilities. This section deals with
basic CGI scripting using COMMAND.COM
. Examples
are used, so make sure you are reading this via your server. If
you are currently reading in local file mode, and your server is running,
click here
to switch to reading via your server.
config.sys
. Here
is a script (basex1.bat
) that would do that:
set OF=%OUTPUT_FILE% echo Content-type: text/plain >%OF% echo. >>%OF% type c:\config.sys >>%OF%And here is the URL that runs the script:
/cgi-bin/basex1.bat
basex2.bat
) that displays the values:
set OF=%OUTPUT_FILE% echo Content-type: text/plain >%OF% echo. >>%OF% echo SOME(!) environment variables set by httpd: >>%OF% echo. >>%OF% echo SERVER_SOFTWARE=%SERVER_SOFTWARE% >>%OF% echo SERVER_NAME=%SERVER_NAME% >>%OF% echo GATEWAY_INTERFACE=%GATEWAY_INTERFACE% >>%OF% echo SERVER_PROTOCOL=%SERVER_PROTOCOL% >>%OF% echo SERVER_PORT=%SERVER_PORT% >>%OF% echo REQUEST_METHOD=%REQUEST_METHOD% >>%OF% echo HTTP_ACCEPT=%HTTP_ACCEPT% >>%OF% echo --- contents --- >>%OF% type %HTTP_ACCEPT% >>%OF% echo ---------------- >>%OF% echo SCRIPT_NAME=%SCRIPT_NAME% >>%OF% echo REMOTE_HOST=%REMOTE_HOST% (blank if no DNS) >>%OF% echo REMOTE_ADDR=%REMOTE_ADDR% >>%OF% echo QUERY_STRING=%QUERY_STRING% (blank if no query in URL) >>%OF% if not %REQUEST_METHOD%==POST goto nopost echo CONTENT_TYPE=%CONTENT_TYPE% >>%OF% echo CONTENT_LENGTH=%CONTENT_LENGTH% >>%OF% echo CONTENT_FILE=%CONTENT_FILE% >>%OF% echo --- contents --- >>%OF% type %CONTENT_FILE% >>%OF% echo. >>%OF% echo ---------------- >>%OF% :nopostAnd here are a few ways run the script and illustrate variations in the environment variables:
Simple execution:
/cgi-bin/basex2.batExecution with a query string:
/cgi-bin/basex2.bat?Query+hereUse a form to POST data:
HTTP_ACCEPT
variable contains the DOS file
path/name of a file containing the client's acceptable types. This is a
deviation from the CGI spec, required on DOS. At present, few scripts
make use of this. However, you might want to check that the MIME type
of the document you are about to send back to the client is in the list
of types acceptable to the client. Otherwise, send an HTML-formatted error
message indicating that the document is indigestible to that client.
echo.
is used in the example after typing
out the POST data file.
COMMAND.COM
. ECHO
does not
provide translation of >
and <
.
This severely limits your flexibility. You cannot directly generate HTML
within the standard DOS shell.
Alternatives do offer the ability
to send angle brackets to standard output, plus far more
capabilities to do other things. Consider switching to some
other shell or interpreter.
Return to the
Scripting Overview